<?php

use yii\db\Migration;

class m180522_012324_create_customer_field_config extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
        }
        $this->createTable('{{%customer_field_config}}', [
            'id' => $this->primaryKey(),
            'code' => $this->string(50)->defaultValue('')->notNull()->comment('字段名'),
            'notes' => $this->string(50)->defaultValue('')->comment('字段注释'),
            'is_required' => $this->smallInteger(1)->defaultValue(0)->notNull()->comment('是否必填 0 否 1是'),
            'type' => $this->string(20)->defaultValue('')->notNull()->comment('类型（text 文本框 select 下拉框 textarea 文本域）'),
            'module' => $this->string(20)->defaultValue('')->notNull()->comment('针对模块 （customer 会员 student 学员）'),
            'admin_id' => $this->integer(11)->defaultValue(0)->notNull()->comment('创建人'),
            'created_at' => $this->integer(11)->defaultValue(0)->notNull()->comment('创建时间'),
            'status' => $this->smallInteger(1)->defaultValue(1)->notNull()->comment('状态（1 启用 2 禁用）'),
            'type_value' => $this->string(255)->defaultValue('')->comment('类型值 （下拉框是用到每个值用空格隔开）'),
        ],$tableOptions);
    }

    public function safeDown()
    {
        $this->dropTable('{{%customer_field_config}}');
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m180522_012324_create_customer_field_config cannot be reverted.\n";

        return false;
    }
    */
}
